// MapUtils.ts
import { fromLonLat, toLonLat } from 'ol/proj';

export class MapUtils {
    // 经纬度转换为地图坐标
    static lonLatToMapCoord(lon: number, lat: number): any {
        return fromLonLat([lon, lat]);
    }

    // 地图坐标转换为经纬度
    static mapCoordToLonLat(coord: [number, number]): any {
        return toLonLat(coord);
    }

    // 获取地图视野范围
    static getMapBounds(map: any): [number, number, number, number] {
        const extent = map.getView().calculateExtent(map.getSize());
        return extent;
    }

    //  获取时间戳
    static getTimestamp(time: string): number {
        return new Date(time).getTime()
    }

    // 获取年月日时分秒
    static getFormateDate(timestamp: number): string {
        const date = new Date(timestamp);
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需要加 1
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');

        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    }
    // 获取年月日时分秒
    static getFormatClock(timestamp: number): string {
        const date = new Date(timestamp);
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');

        return `${hours}:${minutes}:${seconds}`;
    }
}
